package com.xubeihong.xubeihong;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j
@Component
public class CaffeineSchedual {

    @Autowired
    private CacheManager cacheManager;

    @Scheduled(cron = "10/1 54 9 * * ?")
    //@Scheduled(cron = "59 13 23 * * ?")
    public int getTicket() throws ExecutionException, InterruptedException {
        //System.out.println(new Date()+"执行");
        int i = 3;
        while(i>-1){
            Integer ticketCount = (Integer) cacheManager.getCache("ticket").get("num", Integer.class);
            if(null!=ticketCount){
                return 0;
            }
            i--;
            System.out.println(i);
        }
        return 0;
    }

}
